#!/bin/sh
#
# $OpenBSD: Xsession,v 1.1 2016/01/23 13:55:30 ajacoutot Exp $

[ -f ${HOME}/.profile ] && . ${HOME}/.profile

userresources=${HOME}/.Xresources
usermodmap=${HOME}/.Xmodmap
sysresources=/etc/X11/xinit/.Xresources
sysmodmap=/etc/X11/xinit/.Xmodmap

if [ -f ${sysresources} ]; then
    xrdb -merge ${sysresources}
fi

if [ -f ${sysmodmap} ]; then
    xmodmap ${sysmodmap}
fi

if [ -f "${userresources}" ]; then
    xrdb -merge "${userresources}"
fi

if [ -f "${usermodmap}" ]; then
    xmodmap "${usermodmap}"
fi

id1=${HOME}/.ssh/identity
id2=${HOME}/.ssh/id_dsa
id3=${HOME}/.ssh/id_rsa
id4=${HOME}/.ssh/id_ecdsa
id5=${HOME}/.ssh/id_ed25519
if [ -z "${SSH_AGENT_PID}" ]; then
    if [ -x /usr/bin/ssh-agent ] && \
        [ -f ${id1} -o -f ${id2} -o -f ${id3} -o -f ${id4} -o -f ${id5} ]; then
        eval $(ssh-agent -s)
        if [ -z "${SSH_ASKPASS}" ] && \
            [ -x ${LOCALBASE}/lib/seahorse/seahorse-ssh-askpass ]; then
            export SSH_ASKPASS="${LOCALBASE}/lib/seahorse/seahorse-ssh-askpass"
        fi
        ssh-add </dev/null
    fi
fi

eval "${@}"

if [ "${SSH_AGENT_PID}" ]; then 
    ssh-add -D < /dev/null
    eval $(ssh-agent -s -k)
fi      
exit
